package com.hxzy.controller;

import com.changgou.util.Result;
import com.changgou.util.StatusCode;
import com.hxzy.pojo.User;
import com.hxzy.service.UserService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping("/login")
    @PreAuthorize("#user.u_username.equals('zhangsan')")
    public Result login(User user){
        User u  = userService.login(user);
        return new Result(true, StatusCode.OK, "登录成功", u);
    }

    @RequestMapping("/{id}")
    public Result selectById(@PathVariable("id") Integer id){
        System.out.println("进入方法了？？？？");
        User u = userService.findById(id);
        return new Result(true, StatusCode.OK, "查询成功", u);
    }


}
